package com.dynamic.mybatis.core.utils;

import cn.hutool.core.util.StrUtil;

import java.util.Objects;

public class StringUtils {
    public static boolean isEmpty(final CharSequence cs) {
        return cs == null || cs.length() < 1;
    }

    public static boolean isNotEmpty(final CharSequence cs) {
        return !isEmpty(cs);
    }

    public static String getNotEmpty(String... value) {
        if (value == null || value.length < 1) {
            return null;
        }
        for (String v : value) {
            if (isNotEmpty(v)) {
                return v;
            }
        }
        return null;
    }

    public static boolean isEmpty(final Object cs) {
        return cs == null || (cs instanceof CharSequence && isEmpty((CharSequence) cs));
    }

    public static boolean isNotEmpty(final Object cs) {
        return !isEmpty(cs);
    }

    public static boolean isNotBlank(final Object cs) {
        return !isBlank(cs);
    }

    public static boolean isBlank(final Object cs) {
        return cs == null || (cs instanceof CharSequence && isBlank((CharSequence) cs));
    }

    public static String toString(final Object value) {
        return Objects.toString(value, "");
    }

    public static boolean isNotBlank(final CharSequence cs) {
        return !isBlank(cs);
    }

    public static boolean isBlank(final CharSequence cs) {
        if (cs == null) {
            return true;
        }
        int l = cs.length();
        if (l > 0) {
            for (int i = 0; i < l; i++) {
                if (!Character.isWhitespace(cs.charAt(i))) {
                    return false;
                }
            }
        }
        return true;
    }

    /**
     * 字符串驼峰转下划线格式
     *
     * @param name 需要转换的字符串
     * @return 转换好的字符串
     */
    public static String underlineToCamel(String name) {
        return StrUtil.toCamelCase(name);
    }
}
